package lin.zhihong.redme.algorithm;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Homework1 {

    public static void main(String[] args) {

        try (InputStream resourceAsStream = Homework1.class.getClassLoader().getResourceAsStream("homework1.data");
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resourceAsStream))) {
            while (bufferedReader.ready()) {
                String s = bufferedReader.readLine();


                String[] arrays = s.split(",");
                boolean isRepeat = isRepeat(arrays);
                System.out.println(s + "。 是否重复: " + isRepeat);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static boolean isRepeat(String[] arrays) {
        HashMap<String, Integer> countMap = new HashMap<>();

        for (String array : arrays) {
            if (countMap.containsKey(array)) {
                return true;
            }

            countMap.put(array, 1);
        }

        return false;
    }
}
